﻿Public Class CardPresenter

    Dim IQuizEngine As QuizEngine.IQuizEngine

    Sub InitializeQuiz(ByVal quizFile As String)
        IQuizEngine = New QuizEngine.Quiz(quizFile)
    End Sub


    Public Sub Submit_Handler(ByVal page As View.card)
        'page.Question
        GetNextCard(page)
    End Sub

    Public Sub Validate_Handler(ByVal page As View.card)
        Dim quizcard As QuizEntities.QuizCard = page.Card
        InitializeQuiz(page.Quiz_Id)
        If IQuizEngine.ValidateAnswer(quizcard) = page.SelectedAnswer Then
            quizcard.Status.IsCorrectAnswered = True
            quizcard.Status.IsAnswered = True
            quizcard.Status.CorrectQuestionCount = quizcard.Status.CorrectQuestionCount + 1
            page.showAnswer(quizcard)
        Else
            quizcard.Status.IsAnswered = True
            quizcard.Status.IsCorrectAnswered = False
            'quizcard.Status.Score = quizcard.Status.Score + 1
            page.showAnswer(quizcard)
        End If
        'quizcard.Status.IsCorrectAnswered = 

    End Sub


    Public Sub GetNextCard(ByVal page As View.card)
        Dim quizcard As QuizEntities.QuizCard = page.Card
        InitializeQuiz(page.Quiz_Id) ' this line needs a review, as the argument passed was just to supress error.

        '#######################''''''''''''''''''''''''''''''''''''''
        'IQuizEngine.SubmitQuestionCardToCache(quizcard)
        '#######################''''''''''''''''''''''''''''''''''''''
        quizcard = IQuizEngine.GetNextQuestion(quizcard)

        If quizcard.Status.IsLastQuestion Then
            page.ShowResults(quizcard)
            Exit Sub
        End If
        page.ShowQuestionCard(quizcard)
    End Sub

    Public Function GetFirstCard(ByVal quizFile As String) As QuizEntities.QuizCard
        Dim quizcard As New QuizEntities.QuizCard()
        quizcard.QuizUniqueId = quizFile
        InitializeQuiz(quizFile)
        Return IQuizEngine.GetNextQuestion(quizcard)
    End Function

End Class
